package UFFT_package.chart1;



import java.awt.Color;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.Rectangle;
import java.util.ArrayList;

import UFFT_package.Decision1.*;
import UFFT_package.Decision1.Decision;
import javax.swing.JComponent;

class PieValue
{

	    double value;
	    Color color;
	    //color[0]=Color.red;
	    
	    String[] s=new String[] {"Red","Green","Blue"};

	    public PieValue(double value, Color c) 
	    {
	        this.value = value;
	        this.color =c;
	    }
	    
	    public void drawPie(Graphics2D g, Rectangle area, PieValue[] slices) 
	    {
	        // Get total value of all slices
	     //   System.out.println(area.x + " "+ area.y +" "+ area.width + " "+ area.height);
         //   System.out.println(" " +slices.length);	    	
	    	double total = 0.0D;
	        for (int i=0; i<slices.length; i++) 
	        {
	            total += slices[i].value;
	        }

	        // Draw each pie slice
	        double curValue = 0.0D;
	        int startAngle = 0;
	        for (int i=0; i<slices.length; i++) 
	        {
	            // Compute the start and stop angles
	            startAngle = (int)(curValue * 360 / total);
	            int arcAngle = (int)(slices[i].value * 360 / total);

	            // Ensure that rounding errors do not leave a gap between the first and last slice
	            if (i == slices.length-1) 
	            {
	                arcAngle = 360 - startAngle;
	            }

	            // Set the color and draw a filled arc
	            g.setColor(slices[i].color);
	            g.fillArc(area.x, area.y, area.width, area.height, startAngle, arcAngle);
	            
	            curValue += slices[i].value;
	        }
	    }
}

	





public class MyComponent extends JComponent
{
    PieValue[] slices = new PieValue[Decision.num_classes];

    public MyComponent() 
    {
        ArrayList c1=new ArrayList();
        c1.add(Color.blue);
        c1.add(Color.pink);
        c1.add(Color.red);
        c1.add(Color.yellow);
        c1.add(Color.green);
       
        
    	for(int i=0;i<Decision.num_classes;i++) 
         {
        	 slices[i]=new PieValue(Decision.class_count[i],(Color) c1.get(i));
        	 //slices[1]=new PieValue(Decision.class_count[1],Color.green);
        }
    }

    // This method is called whenever the contents needs to be painted
    public void paint(Graphics g) 
    {
        // Draw the pie
        PieValue pv=new PieValue(15,Color.red);
        Rectangle r=new Rectangle(600,100,150,150);
    	pv.drawPie((Graphics2D)g,r,slices);
    	//g.drawString("This is ");
    }

}
